﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJP.Logging;
using WJP;

namespace System
{
    /// <summary>
    /// <see cref="ILogger"/>的扩展
    /// </summary>
    public static class LoggerExtensions
    {
        public static void Log(this ILogger logger, LogLevel level, string message)
        {
            switch (level)
            {
                case LogLevel.Fatal:
                    logger.Fatal(message);
                    break;
                case LogLevel.Error:
                    logger.Error(message);
                    break;
                case LogLevel.Warn:
                    logger.Warn(message);
                    break;
                case LogLevel.Info:
                    logger.Info(message);
                    break;
                case LogLevel.Debug:
                    logger.Debug(message);
                    break;
                default:
                    throw new AppException("Unknown LogSeverity value: " + level);
            }
        }

        public static void Log(this ILogger logger, LogLevel level, string message, Exception exception)
        {
            switch (level)
            {
                case LogLevel.Fatal:
                    logger.Fatal(message, exception);
                    break;
                case LogLevel.Error:
                    logger.Error(message, exception);
                    break;
                case LogLevel.Warn:
                    logger.Warn(message, exception);
                    break;
                case LogLevel.Info:
                    logger.Info(message, exception);
                    break;
                case LogLevel.Debug:
                    logger.Debug(message, exception);
                    break;
                default:
                    throw new AppException("Unknown LogSeverity value: " + level);
            }
        }
    }
}
